﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using Axe.Extensions;
using System.ComponentModel;

namespace Axe.Web.Controls
{
    public class IntegerValidator : RegularExpressionValidator
    {
        public IntegerValidator()
        {
        }

        new string ValidationExpression
        {
            get
            {
                string pattern = "[0-9]+";
                if (AllowNegate)
                    pattern = @"[\-|\+]?" + pattern;
                else
                    pattern = @"\+?" + pattern;
                return pattern;
            }
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            base.ValidationExpression = ValidationExpression;
        }

        [DefaultValue(false), Category("Validation")]
        public bool AllowNegate
        {
            get { return ViewState.Get("AllowNegate",false); }
            set { ViewState["AllowNegate"] = value; }
        }
    }
}
